import java.util.concurrent.TimeUnit;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;


public class Keywords {

	WebDriver myFD = new FirefoxDriver();
	
	
	@Test
	public void myMainTest(){
		myFD.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		navigateBrowser(myFD, "http://www.kayak.co.in/");
		clickElement(myFD, "//a[@id='flights-link']");
		enterText(myFD, "//input[@id='origin']", "Newark (EWR)");
		enterText(myFD, "//input[@id='destination']", "Los Angeles (LAX)");
		checkCheckbox(myFD,"//input[@id='nearbyO']");
	}
	
	
	
	
	public void navigateBrowser(WebDriver driver, String data){
	driver.navigate().to(data);
	}

	public void enterText(WebDriver driver, String xPath, String data){
		driver.findElement(By.xpath(xPath)).clear();
		driver.findElement(By.xpath(xPath)).sendKeys(data);
		}
	
	public String readText(WebDriver driver, String xPath){
		return driver.findElement(By.xpath(xPath)).getText();
		}
	
	public void clickElement(WebDriver driver, String xPath){
		driver.findElement(By.xpath(xPath)).click();
		}
	
	public void selectList(WebDriver driver, String xPath, String data){
		Select myDD = new Select(driver.findElement(By.xpath(xPath)));
	    myDD.selectByVisibleText(data);
	    //driver.findElement(By.cssSelector("option[title=\"5 rooms\"]")).click();
	    myDD = null;
		}

	public void checkCheckbox(WebDriver driver, String xPath){
		if(driver.findElement(By.xpath(xPath)).isSelected()){
			//Do Nothing
		} else {
			driver.findElement(By.xpath(xPath)).click();
			}
		}
	
	
	public void uncheckCheckbox(WebDriver driver, String xPath){
		if(!(driver.findElement(By.xpath(xPath)).isSelected())){
			//Do Nothing
		} else {
			driver.findElement(By.xpath(xPath)).click();
			}
		}
	
}